﻿using AutoMapper;
using WeatherHistory.Api.CommandsQueries.Mapping;
using WeatherHistory.Data.Entities;
using WeatherHistory.Shared.Extensions;

namespace WeatherHistory.Api.CommandsQueries.Queries.Weathers.Search;

public class SearchWeathersQueryWeatherDto : IMapWith<Weather>
{
    public long Id { get; set; }
    public string RegionName { get; set; } = null!;
    public string WeatherCondition { get; set; } = null!;
    public float Temperature { get; set; }
    public float Humidity { get; set; }
    public float WindSpeed { get; set; }
    public float PrecipitationAmount { get; set; }
    public string MeasurementDateTime { get; set; } = null!;
    public List<long> WeatherForecast { get; set; } = null!;

    public void Mapping(Profile profile)
    {
        profile.CreateMap<WeatherRegionRelation, SearchWeathersQueryWeatherDto>()
            .ForMember(dest => dest.Id,
                opt => opt.MapFrom(src => src.RegionId))
            .ForMember(dest => dest.RegionName,
                opt => opt.MapFrom(src => src.Region.Name))
            .ForMember(dest => dest.Temperature,
                opt => opt.MapFrom(src => src.Weather.Temperature))
            .ForMember(dest => dest.Humidity,
                opt => opt.MapFrom(src => src.Weather.Humidity))
            .ForMember(dest => dest.WindSpeed,
                opt => opt.MapFrom(src => src.Weather.WindSpeed))
            .ForMember(dest => dest.WeatherCondition,
                opt => opt.MapFrom(src => src.Weather.WeatherCondition))
            .ForMember(dest => dest.PrecipitationAmount,
                opt => opt.MapFrom(src => src.Weather.PrecipitationAmount))
            .ForMember(dest => dest.MeasurementDateTime,
                opt => opt.MapFrom(src => src.Weather.MeasurementDateTime.ToIso8601String()))
            .ForMember(dest => dest.WeatherForecast,
                opt => opt.MapFrom(src => src.Weather.Forecasts.Select(x => x.Id)));
    }
}